<%@page import="cn.easybuy.entity.Product_category"%>
<%@page import="cn.easybuy.service.impl.Product_categoryServiceimpl"%>
<%@page import="cn.easybuy.service.Product_categoryService"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(function (){
		$.getJSON("LocationServlet","opr=select",call);
		function call(data){
			var $history=$("#tory").html("");
			for(var i=0;i<data.length;i++){
				$history.append("<a title='"+data[i].product_id+"' class='historySou'>"+data[i].name+"</a>");
			}
			
			$(".historySou").click(function (){
				var id=$(this).attr("title");
				location.href="ConmmodityDetailsServlet?opr=productDetils&id="+id;
			});
		}
		
	});
</script>
<div class="top">
	<div class="logo">
		<a href="Index.html"><img src="/EasyBuy/statics/images/logo.png" /> </a>
	</div>
	<div class="search">
		<form>
			<input type="text" value="" class="s_ipt" /> <input type="button"
				value="搜索" class="s_btn" />
		</form>
		<span class="fl" id="tory">
		</span>
	</div>
	<div class="i_car" id="buyCarCount">
		<div class="car_bg" id="product">
			<c:choose>
				<c:when test="${ !empty applicationScope.id}">
					<div class='un_login'>还未登录！<a href='/EasyBuy/pre/Login.jsp' style='color:#ff4e00;'>马上登录</a> 查看购物车！"</div>
				</c:when>
			</c:choose>
			<!-- 购物车信息 -->
		</div>
	</div>
</div>
<!--End Header End-->
<!--Begin Menu Begin-->
<div class="menu_bg">
	<div class="menu">
		<!--Begin 商品分类详情 Begin-->
		<div class="nav">
			<div class="nav_t">全部商品分类</div>
			<div class="leftNav">
				<ul id="s">
					<c:set var="a" value="-80"></c:set>
					<c:forEach items="${productCategoryLists }" var="one">
						<li class="oneLevelP" title="${one.id }">
							<div class="fj">
								<span class="n_img"><span></span> <img alt="" src="" />
								</span> <span class="fl"> ${one.name } </span>
							</div> <c:set var="a" value="${a+40 }"></c:set>
							<div class="zj" style="top:-${a+40 }px;">
								<div class="zj_l">
									<c:forEach items="${one.productCategoryTwo }" var="two">
										<div class="zj_l_c">
                                    		<h2>${two.name }</h2>
											<c:forEach items="${two.productCategoryThree }" var="three">
                                    			<a href="/EasyBuy/IndexServlet?opr=categoryThreeNames&id=${three.id }&name=${three.name}">${three.name }</a>|
                                    		</c:forEach>
                                		</div>
									</c:forEach>
								</div>
								<div class="zj_r">
									<a href="/EasyBuy/pre/product/CategoryList.jsp"> <img src="/EasyBuy/statics/images/n_img1.jpg"
										width="236" height="200" /> </a> <a href="/EasyBuy/pre/product/CategoryList.jsp"> <img
										src="/EasyBuy/statics/images/n_img2.jpg" width="236" height="200" />
									</a>
								</div>
							</div>
						</li>
					</c:forEach>
				</ul>
			</div>
		</div>
		<!--End 商品分类详情 End-->
		<ul class="menu_r">
			<li><a href="/EasyBuy/pre/Index.jsp">首页</a>
			<c:forEach items="${teTypes }" var="te">
				<li><a name="${te.id }" class="oneType">${te.name }</a></li>
			</c:forEach>
			<a href="/EasyBuy/pre/product/Sell.jsp">团购</a>
			</li>
		</ul>
		<div class="m_ad">中秋送好礼！</div>
	</div>
</div>

<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$(".oneType").click(function(){
			var id=$(this).attr("name");
			var str=document.URL;
			if(str.substring(str.lastIndexOf("/")+1)=="CategoryList.jsp"){
				$(".cate_list").html("");
				$.getJSON("ConmmodityListServlet","opr=categoryListNo&id="+id,callBack);
				function callBack(data){
					for(var i=0;i<data.length;i++){
						$(".cate_list").append("<li>"+
								"<div class='img'>"+
									"<a href='ConmmodityDetailsServlet?opr=productDetils&id="+data[i].id+"'><img src='/EasyBuy/statics/images/"+data[i].fileName+"' "+
									"width='210' height='185' />"+
									"</a>"+
								"</div>"+
								"<div class='price'>"+
									"<font>￥<span>"+data[i].price+"</span>"+
									"</font>&nbsp;"+data[i].integral+"R"+
								"</div>"+
								"<div class='name'>"+
									"<a href='#'>"+data[i].name+"</a>"+
								"</div>"+
								"<div class='carbg'>"+
									"<a class='ss' title='"+data[i].id+"'>收藏</a> <a title='"+data[i].id+"' class='j_car'>加入购物车</a>"+
								"</div>"+
							"</li>");
					}
					shouCang();
					addCar();
					$("#sheng").click(function(){
			
			
				$.getJSON("ConmmodityListServlet","opr=categorySheng&id="+id+"&level=1",callBackShengC);
			
			function callBackShengC(dataShengC){
				$(".cate_list").html("");
						for ( var i = 0; i < dataShengC.length; i++) {
							$(".cate_list").append("<li>"
								+ "<div class='img'>"
								+ "<a href='ConmmodityDetailsServlet?opr=productDetils&id="
								+ dataShengC[i].id
								+ "'><img src='/EasyBuy/statics/images/"+dataShengC[i].fileName+"' "+
								"width='210' height='185' />"
								+ "</a>"
								+ "</div>"
								+ "<div class='price'>"
								+ "<font>￥<span>"
								+ dataShengC[i].price
								+ "</span>"
								+ "</font>&nbsp;"
								+ dataShengC[i].integral
								+ "R"
								+ "</div>"
								+ "<div class='name'>"
								+ "<a href='#'>"
								+ dataShengC[i].name
								+ "</a>"
								+ "</div>"
								+ "<div class='carbg'>"
								+ "<a class='ss' title='"+dataShengC[i].id+"'>收藏</a> <a title='"+dataShengC[i].id+"' class='j_car'>加入购物车</a>"
								+ "</div>"
								+ "</li>");
						}
						shouCang();
						addCar();
			}
		});
		$("#jiang").click(function(){
			
				$.getJSON("ConmmodityListServlet","opr=categoryJiang&id="+id+"&level=1",callBackJiangC);
			
			function callBackJiangC(dataJiangC){
				$(".cate_list").html("");
						for ( var i = 0; i < dataJiangC.length; i++) {
							$(".cate_list").append("<li>"
								+ "<div class='img'>"
								+ "<a href='ConmmodityDetailsServlet?opr=productDetils&id="
								+ dataJiangC[i].id
								+ "'><img src='/EasyBuy/statics/images/"+dataJiangC[i].fileName+"' "+
								"width='210' height='185' />"
								+ "</a>"
								+ "</div>"
								+ "<div class='price'>"
								+ "<font>￥<span>"
								+ dataJiangC[i].price
								+ "</span>"
								+ "</font>&nbsp;"
								+ dataJiangC[i].integral
								+ "R"
								+ "</div>"
								+ "<div class='name'>"
								+ "<a href='#'>"
								+ dataJiangC[i].name
								+ "</a>"
								+ "</div>"
								+ "<div class='carbg'>"
								+ "<a class='ss' title='"+dataJiangC[i].id+"'>收藏</a> <a title='"+dataJiangC[i].id+"' class='j_car'>加入购物车</a>"
								+ "</div>"
								+ "</li>");
						}
						shouCang();
						addCar();
			}
		});
		$("#xiaoShang").click(function(){
			
				$.getJSON("ConmmodityListServlet","opr=categoryShang&id="+id+"&level=1",callBackShangC);
			
			function callBackShangC(dataShangC){
				$(".cate_list").html("");
						for ( var i = 0; i < dataShangC.length; i++) {
							$(".cate_list").append("<li>"
								+ "<div class='img'>"
								+ "<a href='ConmmodityDetailsServlet?opr=productDetils&id="
								+ dataShangC[i].id
								+ "'><img src='/EasyBuy/statics/images/"+dataShangC[i].fileName+"' "+
								"width='210' height='185' />"
								+ "</a>"
								+ "</div>"
								+ "<div class='price'>"
								+ "<font>￥<span>"
								+ dataShangC[i].price
								+ "</span>"
								+ "</font>&nbsp;"
								+ dataShangC[i].integral
								+ "R"
								+ "</div>"
								+ "<div class='name'>"
								+ "<a href='#'>"
								+ dataShangC[i].name
								+ "</a>"
								+ "</div>"
								+ "<div class='carbg'>"
								+ "<a class='ss' title='"+dataShangC[i].id+"'>收藏</a> <a title='"+dataShangC[i].id+"' class='j_car'>加入购物车</a>"
								+ "</div>"
								+ "</li>");
						}
						shouCang();
						addCar();
			}
		});
		$("#xiaoXia").click(function(){
			
				$.getJSON("ConmmodityListServlet","opr=categoryXia&id="+id+"&level=1",callBackXiaC);
			
			function callBackXiaC(dataXiaC){
				$(".cate_list").html("");
						for ( var i = 0; i < dataXiaC.length; i++) {
							$(".cate_list").append("<li>"
								+ "<div class='img'>"
								+ "<a href='ConmmodityDetailsServlet?opr=productDetils&id="
								+ dataXiaC[i].id
								+ "'><img src='/EasyBuy/statics/images/"+dataXiaC[i].fileName+"' "+
								"width='210' height='185' />"
								+ "</a>"
								+ "</div>"
								+ "<div class='price'>"
								+ "<font>￥<span>"
								+ dataXiaC[i].price
								+ "</span>"
								+ "</font>&nbsp;"
								+ dataXiaC[i].integral
								+ "R"
								+ "</div>"
								+ "<div class='name'>"
								+ "<a href='#'>"
								+ dataXiaC[i].name
								+ "</a>"
								+ "</div>"
								+ "<div class='carbg'>"
								+ "<a class='ss' title='"+dataXiaC[i].id+"'>收藏</a> <a title='"+dataXiaC[i].id+"' class='j_car'>加入购物车</a>"
								+ "</div>"
								+ "</li>");
						}
						shouCang();
						addCar();
			}
		});
		$("#xin").click(function(){
			$.getJSON("ConmmodityListServlet","opr=categoryXin&id="+id+"&level=1",callBackXinC);
			
			function callBackXinC(dataXinC){
				$(".cate_list").html("");
						for ( var i = 0; i < dataXinC.length; i++) {
							$(".cate_list").append("<li>"
								+ "<div class='img'>"
								+ "<a href='ConmmodityDetailsServlet?opr=productDetils&id="
								+ dataXinC[i].id
								+ "'><img src='/EasyBuy/statics/images/"+dataXinC[i].fileName+"' "+
								"width='210' height='185' />"
								+ "</a>"
								+ "</div>"
								+ "<div class='price'>"
								+ "<font>￥<span>"
								+ dataXinC[i].price
								+ "</span>"
								+ "</font>&nbsp;"
								+ dataXinC[i].integral
								+ "R"
								+ "</div>"
								+ "<div class='name'>"
								+ "<a href='#'>"
								+ dataXinC[i].name
								+ "</a>"
								+ "</div>"
								+ "<div class='carbg'>"
								+ "<a class='ss' title='"+dataXinC[i].id+"'>收藏</a> <a title='"+dataXinC[i].id+"' class='j_car'>加入购物车</a>"
								+ "</div>"
								+ "</li>");
						}
						shouCang();
						addCar();
			}
		});
				}
			}else{
				$(this).attr("href","/EasyBuy/ConmmodityListServlet?opr=categoryList&id="+id);
			}
		});
		function shouCang(){
			$(".ss").click(function(){
			var productId=$(this).attr("title");
			var userId=$(".user").attr("title");
			$.getJSON("/EasyBuy/CollectServlet","opr=categoryShou&productId="+productId+"&userId="+userId,callBackShou);
			function callBackShou(dataShou){
				if(dataShou=="have"){
					alert("已有该收藏");
				}else if(dataShou=="success"){
					alert("收藏成功");
				}else if(dataShou=="error"){
					alert("收藏失败");
				}
			}
		});
		}
		//加入购物车
		function addCar(){
			$(".j_car").click(function(){
			var productId=$(this).attr("title");
			var userId=$(".user").attr("title");
			add();
			function add(){
				$.get("BuyCarServlet","opr=addBuyCar&uId="+userId+"&pId="+productId+"&pNum=1",function(data){
					if(data == "cg"){
						alert("添加成功");
					}else if(data=="sb"){
						alert("添加失败");
					}
				});
			}
		});	
		}
		$(".oneLevelP").click(function(){
			var id=$(this).attr("title");
			location.href="ConmmodityListServlet?opr=category&id="+id;
		});
		//购物车总条数
		function cou(){
			$.get("IndexServlet","opr=seleCount&uId=${applicationScope.id}",function(data){
				$("#buyCarCount").append("<div class='car_t'>"+
				"购物车 [ <span>"+data+"</span> ]"+
				"</div>");
			});
		}
		cou();
		
		//购物车显示
		function product(){
			$.getJSON("IndexServlet","opr=productNPFinfo&userid=${applicationScope.id}",productcallBack);
		}
		function productcallBack(data){
			var $ulli=$("#product").html("");
			//$ulli.append("<div class='un_login'>还未登录！<a href='/EasyBuy/pre/Login.jsp' style='color:#ff4e00;'>马上登录</a> 查看购物车！</div>");
			for(var i=0;i<data.length;i++){
				$ulli.append("<ul class='cars'>"+
				"<li>"+
					"<div class='img'>"+
						"<a href='#'><img src='/EasyBuy/statics/images/"+data[i].fileName+
							"' width='58' height='58' /> </a>"+
					"</div>"+
					"<div class='name'>"+
						"<a href='#'>"+data[i].name+"</a>"+
					"</div>"+
					"<div class='price'>"+
						"<font color='#ff4e00'>￥"+data[i].price+"</font> X"+data[i].productNum+
					"</div>"+
				"</li>"+
			"</ul>");
			if(i==data.length-1){
				$ulli.append("<div class='price_sum'>"+
				"共计&nbsp; <font color='#ff4e00'>￥</font><span>"+data[i].productZongSum+"</span>"+
			"</div>"+
			"<div class='price_a'>"+
				"<a href='/EasyBuy/pre/settlement/BuyCar.jsp'>去购物车结算</a>"+
			"</div>");
			}
			
			}
			
		}
		product();
		$(".s_btn").click(function(){
			var name=$(".s_ipt").val();
			location.href="/EasyBuy/pre/product/VagueList.jsp?name="+name;
		});
		function hideType() {
			$(".leftNav").hide();
		}
	});
</script>


